<?php
namespace Home\Controller;
use Think\Controller;
class IntegralController extends Controller {


    /**
     * 我的积分
     */
      public function myintegral(){
       $member_id = I("post.uid");
       $member = M("member");
       $memberinfo = $member ->field("member_id,member_points")->where(array("member_id"=>$member_id))->find();
        if(!$memberinfo){
            returnArr('数据为空');
        }else{
            returnApiSuccess('ok',$memberinfo);
        }
   }
     /**
      * 积分明细
      */
        public function intergrallog() {
        $member_id = I("post.uid");
        $option = I("post.option");
        $pindex = I('post.pno', 1, 'intval');     //当前页码
        $psize = I('post.pgz', 10, 'intval');   //显示条数
        if (!$pindex)
        $pindex = 1;
        $pfirst = ($pindex - 1) * $psize;
        $points_log = M("points_log");
        $where["pl_memberid"] = $member_id;

        if ($option == 1) {
            $where["pl_points"] = array("lt", 0);
        } else if ($option == 2) {
            $where["pl_points"] = array("gt", 0);
        }
        $pointsinfo = $points_log->field("pl_points,pl_desc,pl_stage,pl_addtime")->where($where)->limit($pfirst .','.$psize)->order(array('pl_id'=>'desc'))->select();
        $tagearr = $this->tage();
        foreach ($pointsinfo as $k=>$tage){
            $pointsinfo[$k]["pl_tagename"]= $tagearr[$tage["pl_stage"]] ;
            if($tage["pl_stage"] =="order"){
            $pointsinfo[$k]["pl_ordersn"]= str_replace(array("订单","购物消费"),"",$tage["pl_desc"]);
            }
        }
        if (!$pointsinfo) {
            returnArr('数据为空');
        } else {
            returnApiSuccess('ok', $pointsinfo);
        }
    }
    public function tage(){
        return array(
               "order"=>"消费赠送",
               "signin"=>"签到奖励",
               "regist"=>"注册送礼",
               "login"=>"每天登录送积分",
               "comments"=>"商品评论",
               "app" =>"积分兑换"
            );
    }
}

